package com.xlchen.controller.admin;

import com.xlchen.dao.AdminGoodsDao;
import com.xlchen.dao.AdminTypeDao;
import com.xlchen.dao.IndexDao;
import com.xlchen.po.Goods;
import com.xlchen.po.GoodsType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;

import java.util.List;

@Controller("testController")
public class TestController {
    @Autowired
    private AdminGoodsDao adminGoodsDao;
    @Autowired
    private AdminTypeDao adminTypeDao;
    @Autowired
    private IndexDao indexDao;


    public void testSelect(){
        List<Goods> list =  adminGoodsDao.selectGoods();
        Goods goods2 = adminGoodsDao.selectGoodsById(12);
        for(Goods goods:list){
            System.out.println(goods);
        }
        System.out.println(goods2);
    }

    public void testAdd(){
        //id,gname,goprice,grprice,gstore,gpicture,goodstype_id
        Goods goods = new Goods();
        goods.setGname("波司登");
        goods.setGoprice(200D);
        goods.setGrprice(300D);
        goods.setGstore(900);
        goods.setGpicture("boy");
        goods.setGoodstype_id(3);
        adminGoodsDao.addGoods(goods);
    }

    public void testTypeSelect(){
        List<GoodsType> goodsTypes = adminTypeDao.selectGoodsType();
        for(GoodsType goodsType:goodsTypes){
            System.out.println(goodsType);
        }
    }

    //测试删除类型
    public void testTypeDelete(){
        adminTypeDao.deleteType(6);
    }

    //测试按照类型查找商品
    public void testSelectGoodsByType(){
        List<Goods> goods = adminTypeDao.selectGoodsByType(2);
        for(Goods goods1:goods){
            System.out.println(goods1);
        }
    }

    //测试最新商品功能
    public void testSelectLastGoods(){
      /*  List<Goods> goods = indexDao.getLastedGoods();
        for(Goods goods1:goods){
            System.out.println(goods1);
        }*/
    }
}
